package app.view.mediators
{
	import app.AppConstants;
	
	import flash.events.MouseEvent;
	
	import mx.containers.ApplicationControlBar;
	import mx.controls.Button;
	
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	
	public class MenuBarMediator extends Mediator
	{
		
		public static const NAME:String ="MenuBarMediator";
		

		public function MenuBarMediator( view:Object )
		{
			super(NAME, view);
		}
		
		override public function onRegister():void{
			view.addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function onClick(event:MouseEvent):void{
			var target:Button = event.target as Button;
			if(!target)return;
			switch( target.name){
				case "openJSON":
					sendNotification(AppConstants.OPEN_JSON);
					break;
				case "decodeJSON":
					sendNotification(AppConstants.DECODE_JSON);
					break;
				case "openXML":
					sendNotification(AppConstants.OPEN_XML);
					break;
					
				case "decodeXML":
					sendNotification(AppConstants.DECODE_XML);
					break;
					
					
								
			} 
		}
		
	
		
		
		public function get view():ApplicationControlBar{
			return ApplicationControlBar( viewComponent );
		}
		
	}
}